package com.xiaoyu.shenyou.shenyouv1.controller;

import com.xiaoyu.shenyou.shenyouv1.common.result.Result;
import com.xiaoyu.shenyou.shenyouv1.entity.PredNameEntity;
import com.xiaoyu.shenyou.shenyouv1.entity.PredictionEntity;
import com.xiaoyu.shenyou.shenyouv1.services.PredictionService;
import com.xiaoyu.shenyou.shenyouv1.vo.PredictionVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@Slf4j
@RequestMapping("/api/v1/prediction")
public class PredictionController {
    @Autowired
    private PredictionService predictionService;


    /**
     * 指定名字查询算法
     *
     * @param id
     * @return
     */
    @GetMapping("/list/{id}/{name}")
    public Result predictions(@PathVariable int id, @PathVariable String name) {

        List<PredictionEntity> predictionEntities = predictionService.selectPredic(id, name);
        PredictionVO predictionVO = new PredictionVO();
        double calculatePercent = predictionService.calculatePercent(predictionEntities);
        predictionVO.setPredictionEntities(predictionEntities).setSuccessPercent(calculatePercent);
        Result<PredictionVO> success = Result.success(predictionVO);
        return success;
    }

    /**
     * 查询所有算法名字和胜率
     *
     * @param id
     * @return
     */
    @GetMapping("/list/names/{id}")
    public Result names(@PathVariable int id) {
        List<PredNameEntity> predNameEntities = predictionService.selectPredicName(id);
        Result<List<PredNameEntity>> success = Result.success(predNameEntities);
        return success;
    }

}
